******SET YOUR DIRECTORY to ...\replication


clear all
set more off

use "finaldata\final_cc_data.dta", clear

set matsize 2000

drop if fipsplace_00==.
xtset fipsplace_00 year

drop if year>1991

***Merge with employment decentralization
merge 1:1 fipsplace_00 year using "finaldata\data_cbp.dta"
drop _merge

drop if fipsplace_00==.
xtset fipsplace_00 year

*Create instrument and outcome
g good_soil = (ph1_plc_wtm_wtm_0_r>=6.8 & ph1_plc_wtm_wtm_0_r<=7.7)
gen inter_badtetra=(1-good_soil)*tetra_corr
gen l10inter_badtetra=L10.inter_badtetra
g perc_cc =  tot_cc_oripop_corr / (tot_ncc_oripop_corr + tot_cc_oripop_corr)

*Create independent variables
gen vc_pc=totnpcc_cc_offenses_vc * 1000
gen l10perc_cc=L10.perc_cc 
gen l10perc_empl_ctycc_sic20= L10.perc_empl_ctycc_sic20

*Label variables
label var vc_pc "Violent crime"
label var inter_badtetra "High LB x Lead"
label var l10inter_badtetra "High LB x Lead (10 years lag)"
label var l10perc_cc "Share Pop CC (10 years lag)"
label var l10perc_empl_ctycc_sic20  "Share Manuf CC (10 years lag)"
label var perc_cc "Sh. Pop CC"

***Regressions (long)
ivreghdfe perc_empl_ctycc_sic20 (vc_pc=inter_badtetra), absorb(fipsplace_00 year)
local ff= string(round(e(cdf),.01) , "%9.2f")
outreg2 vc_pc using table4, tex(frag) nocon noni nor2 nonotes label ctitle("Share Manuf CC") addtext(High LB x Lead 29 years lag, NO, F, `ff')  replace
ivreghdfe perc_empl_ctycc_sic20 l10perc_cc l10inter_badtetra (vc_pc=inter_badtetra), absorb(fipsplace_00 year)
local ff= string(round(e(cdf),.01) , "%9.2f")
outreg2 vc_pc l10perc_cc using table4, tex(frag) nocon noni nor2 nonotes label keep(vc_pc l10perc_cc) ctitle("Share Manuf CC") addtext(High LB x Lead 29 years lag, YES, F, `ff')

ivreghdfe perc_cc (vc_pc=inter_badtetra) if year>=1974, absorb(fipsplace_00 year)
local ff= string(round(e(cdf),.01) , "%9.2f")
outreg2 vc_pc using table4, tex(frag) nocon noni nor2 nonotes label ctitle("Share Pop CC") addtext(High LB x Lead 29 years lag, NO, F, `ff')
ivreghdfe perc_cc l10perc_empl_ctycc_sic20 l10inter_badtetra (vc_pc=inter_badtetra), absorb(fipsplace_00 year)
local ff= string(round(e(cdf),.01) , "%9.2f")
outreg2 vc_pc l10perc_empl_ctycc_sic20 using table4, tex(frag) nocon noni nor2 nonotes label keep(vc_pc l10perc_empl_ctycc_sic20) ctitle("Share Pop CC") addtext(High LB x Lead 29 years lag, YES, F, `ff')
